/** @file
  The description of UART.

  Copyright (C) 2022, Phytium Technology Co., Ltd. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Platform.h>

Scope(_SB)
{
  //UART 1
  Device(UAR1) {
    Name(_HID, "ARMH0011")
    Name(_UID, 1)
    Name(_CRS, ResourceTemplate() {
      QWordMemory (
        ResourceProducer,      // Resource Usage
        PosDecode,             // Decode
        MinFixed,              // IsMinFixed
        MaxFixed,              // IsMaxFixed
        NonCacheable,
        ReadWrite,
        0x00000000,            // Granularity
        UART1_BASE,            // Min Base Address
        UART1_BASE_MAX,        // Max Base Address
        0x00000000,            // Translate
        0x00001000,            // Length
        , , BUFF
        )

      Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 47 }
    })
  }

  Method(TCOM, 1, Serialized) {
    OperationRegion(
      COM0,
      SystemMemory,
      UART1_BASE,
      0x1000
      )
    Field(COM0, DWordAcc, NoLock, Preserve) {
      DAT8,
      8,
      Offset(0x05),
      ,
      5,
      TRDY,
      1,
    }

  Add(SizeOf(Arg0), One, Local0)
  Name(BUF0, Buffer(Local0){})
  Store(Arg0, BUF0)
  store(0, Local1)
  Decrement(Local0)
  While(LNotEqual(Local1, Local0)){
    while(LEqual(TRDY, ONE)){}
      Store(DerefOf(Index(BUF0, Local1)), DAT8)
      Increment(Local1)
    }
  }

  Method(DBGC, 3, Serialized) {
    Name(CRLF, Buffer(2){0x0D, 0x0A})
    TCOM(Arg1)
    if(LEqual(Arg0, 2)){
      TCOM(ToHexString(Arg2))
    }
    TCOM(CRLF)
  }
}
